﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QuanLyBanHang.DAL;
using QuanLyBanHang.VO;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;

namespace QuanLyBanHang.BUS
{
    public class NhanVien_BUS
    {
        NhanVien_DAL nv_dal = new NhanVien_DAL();
        public NhanVien_VO Validate(string tk, string mk)
        {
            try
            {
                DataTable dt = new DataTable();
                dt = nv_dal.ValidateUser(tk, mk);
                if (dt != null)
                {
                    NhanVien_VO nv = new NhanVien_VO();
                    nv.MaNV = int.Parse(dt.Rows[0][0].ToString());
                    nv.hoten = dt.Rows[0][1].ToString();
                    nv.quyen = int.Parse(dt.Rows[0][7].ToString());
                    return nv;
                }
                else return null;
            }
            catch
            {
                MessageBox.Show("Sai tài khoản hoặc mật khẩu");
                return null;
            }
        }
        public int trungTK(string tk)
        {
            DataTable dt = new DataTable();
            dt = nv_dal.getTK(tk);
            if ((dt != null) && (dt.Rows.Count > 0)) return dt.Rows.Count;
            return 0;
        }
        public string layTK(int  id)
        {
            DataTable dt = new DataTable();
            dt = nv_dal.getTKfromID(id);
            if ((dt != null) && (dt.Rows.Count > 0)) return dt.Rows[0][0].ToString();
            return null;
        }
    }
}

